package com.yanqu.road.server.cmd.activity.entername;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.entername.EnterNameActivityConfig;
import com.yanqu.road.server.manger.activity.entername.EnterNameActivityMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ENTER_NAME_DISPERSE_GOLD_GET, desc = "领取散财")
public class EnterNameGetDisperseGoldRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        EnterNameProto.GetEnterNameDisperseGoldRewardReqMsg reqMsg = EnterNameProto.GetEnterNameDisperseGoldRewardReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        EnterNameActivityConfig config = EnterNameActivityMgr.getActivityConfig(activityId);
        if(config != null && ActivityMgr.activityInCanRewardPeriod(config.getActivityInfo())){
            EnterNameProto.ChannelGetEnterNameDisperseGoldRewardReqMsg.Builder builder = EnterNameProto.ChannelGetEnterNameDisperseGoldRewardReqMsg.newBuilder();
            builder.setActivityId(activityId);
            builder.setUserKey(EnterNameActivityMgr.buildKeyMsg(packet.getPlayerId()));
            player.sendChannelPacket(Protocol.N_ENTER_NAME_GET_DISPERSE_GOLD_REWARD, builder);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
